# -*- coding: utf-8 -*-
import sys
from PySide import QtGui
from PySide import QtCore
import win32gui
import win32con
import ctypes

class Window(QtGui.QWidget):
    def __init__(self, parent=None):
        super(Window, self).__init__()
        
        self.check = QtGui.QCheckBox('top', self)
        self.label = QtGui.QLabel('label', self)
        self.check.stateChanged.connect(self.top_triggle)
        
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.check)
        layout.addStretch(1)
        layout.addWidget(self.label)
        self.setLayout(layout)
        
        ctypes.pythonapi.PyCObject_AsVoidPtr.restype = ctypes.c_void_p
        ctypes.pythonapi.PyCObject_AsVoidPtr.argtypes = [ctypes.py_object]
        self.hwnd = ctypes.pythonapi.PyCObject_AsVoidPtr(self.winId())
        
    def top_triggle(self, state):
        if state == QtCore.Qt.Checked:
            hWndInsertAfter = win32con.HWND_TOPMOST
        else:
            hWndInsertAfter = win32con.HWND_NOTOPMOST
        win32gui.SetWindowPos(self.hwnd, hWndInsertAfter, 0, 0, 0, 0, 
            win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    widget = Window()
    widget.show()
    sys.exit(app.exec_())
